package com.longan.goods.controller;

import com.longan.common.model.goods.entity.Activity;
import com.longan.common.model.goods.entity.BigCategory;
import com.longan.common.model.goods.entity.Goods;
import com.longan.common.model.goods.entity.MiddleCategory;
import com.longan.common.utils.AjaxResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@RequestMapping("/goods")
@RestController
public class GoodsController {

    @GetMapping("/page")
    public AjaxResult page() {
        return AjaxResult.success();
    }

    @GetMapping("/category")
    public AjaxResult category() {
        List<BigCategory> bigCategoryList = new ArrayList<>();
        BigCategory bigCategory1 = new BigCategory();
        bigCategory1.setId("100");
        bigCategory1.setCategoryName("大家电");
        BigCategory bigCategory2 = new BigCategory();
        bigCategory2.setId("200");
        bigCategory2.setCategoryName("食品饮料");
        BigCategory bigCategory3 = new BigCategory();
        bigCategory3.setId("300");
        bigCategory3.setCategoryName("女鞋零");

        BigCategory bigCategory4 = new BigCategory();
        bigCategory4.setId("400");
        bigCategory4.setCategoryName("女鞋一");

        BigCategory bigCategory5 = new BigCategory();
        bigCategory5.setId("500");
        bigCategory5.setCategoryName("女鞋二");

        BigCategory bigCategory6 = new BigCategory();
        bigCategory6.setId("600");
        bigCategory6.setCategoryName("男鞋");

        bigCategoryList.add(bigCategory1);
        bigCategoryList.add(bigCategory2);
        bigCategoryList.add(bigCategory3);

        bigCategoryList.add(bigCategory4);
        bigCategoryList.add(bigCategory5);
        bigCategoryList.add(bigCategory6);
        return AjaxResult.success(bigCategoryList);
    }

    @GetMapping("/middle_class")
    public AjaxResult middleClass(String bigClassName) {
        List<MiddleCategory> middleCategoryList = new ArrayList<>();
        MiddleCategory bigCategory1 = new MiddleCategory();
        bigCategory1.setId("100");
        bigCategory1.setCategoryName("热水器");
        bigCategory1.setUrl("http://longanweb.top:8089/allfile/jd/rsq.jpg");
        MiddleCategory bigCategory2 = new MiddleCategory();
        bigCategory2.setId("200");
        bigCategory2.setCategoryName("洗衣机");
        bigCategory2.setUrl("http://longanweb.top:8089/allfile/jd/xyj.jpg");
        MiddleCategory bigCategory3 = new MiddleCategory();
        bigCategory3.setId("300");
        bigCategory3.setCategoryName("洗碗机");
        bigCategory3.setUrl("http://longanweb.top:8089/allfile/jd/xwj.jpg");
        MiddleCategory bigCategory4 = new MiddleCategory();
        bigCategory4.setId("400");
        bigCategory4.setCategoryName("油烟机");
        bigCategory4.setUrl("http://longanweb.top:8089/allfile/jd/yyj.jpg");
        MiddleCategory bigCategory5 = new MiddleCategory();
        bigCategory5.setId("500");
        bigCategory5.setCategoryName("冰箱");
        bigCategory5.setUrl("http://longanweb.top:8089/allfile/jd/xdg.jpg");
        MiddleCategory bigCategory6 = new MiddleCategory();
        bigCategory6.setId("600");
        bigCategory6.setCategoryName("音响");
        bigCategory6.setUrl("http://longanweb.top:8089/allfile/jd/yx.jpg");
        middleCategoryList.add(bigCategory1);
        middleCategoryList.add(bigCategory2);
        middleCategoryList.add(bigCategory3);
        middleCategoryList.add(bigCategory4);
        middleCategoryList.add(bigCategory5);
        middleCategoryList.add(bigCategory6);
        return AjaxResult.success(middleCategoryList);
    }

    @GetMapping("/activity")
    public AjaxResult activity(String bigClassName) {
        List<Activity> activityList = new ArrayList<>();
        Activity activity1 = new Activity();
        activity1.setActivityName("");
        activity1.setId("1000");
        activity1.setUrl("http://longanweb.top:8089/allfile/jd/hd01.jpg");

        Activity activity2 = new Activity();
        activity2.setActivityName("");
        activity2.setId("1000");
        activity2.setUrl("http://longanweb.top:8089/allfile/jd/hd02.jpg");

        activityList.add(activity1);
        activityList.add(activity2);
        return AjaxResult.success(activityList);
    }

    @GetMapping("/goods")
    public AjaxResult goods(@RequestParam(defaultValue = "1") Integer pageNum,
                            @RequestParam(defaultValue = "10") Integer pageSize) {
        List<Goods> goodsList = new ArrayList<>();
        for (int i = 0; i < 10000; i++) {
            Goods goods = new Goods();
            goods.setId(String.valueOf(i));
            goods.setGoodsName("商品" + i);
            goods.setGoodsImg("http://longanweb.top:8089/allfile/jd/rsq.jpg");
            goodsList.add(goods);
        }
        List<Goods> subList = goodsList.stream().skip((long) (pageNum - 1) * pageSize).limit(pageSize).
                collect(Collectors.toList());
        return AjaxResult.success(subList);
    }
}
